def is_prime(num):
  if num <= 1:
    return False
  for i in range(2, int(num**0.5) + 1):
    if num % i == 0:
      return False
  return True

number = input()

if len(number) != 4 or not number.isdigit():
  print(0)
else:
  max_prime = 0
  for i in range(4):
    for j in range(i + 1, 5):
      num = int(number[i:j])
      if is_prime(num) and num > max_prime:
        max_prime = num
  print(max_prime)
